<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Hello World</title>
  <script src="https://unpkg.com/vue"></script>

</head>

<body>
  <div id="root"></div>
  <script>
    /* 
      1. v-model双向数据绑定实现原理
      - 通过绑定数据和事件实现
      - props必须声明为modelValue
      - 事件名为update:modelValue
    */

    const app = Vue.createApp({
      data() {
        return {
          count: 0
        }
      },
      template: `<div>
        <counter v-model="count" />
      </div>`
    })
    app.component('counter', {
      props: ['modelValue'],
      template: `<div>
                  {{modelValue}}
                  <button @click="handleClick">自增</button>
                </div>`,
      methods: {
        handleClick() {
          this.$emit('update:modelValue', this.modelValue + 3)
        }
      }
    })
    const vm = app.mount('#root');
  </script>
</body>

</html>